{{extend 'layout.html'}}

<script type="text/javascript">

	jQuery(document).ready(function(){
		jQuery('textarea').css('width','500px').css('height','30px');	
	});
	
</script> 


<script type="text/javascript">

	function setLikeButton(element){		
		element.parent().html("<button class='btn disabled' type='button'><i class='icon-thumbs-up shaded'></i>{{=T('Ti piace')}}</button>");
	}
	
	function commentPost(textarea, post, div_respond){		
		jQuery.ajax({
			url: "{{=URL(r=request, c='default', f='commentPost')}}",
			data: {commento: textarea.val(), post_id:post},
			success: function(data){
				div_respond.append(data);
				textarea.val('');
			}
		});
	}

</script>


	
<div class="module">
	<div class="module-body">
		<div class="stream-composer media">
			<a class="media-avatar medium pull-left" href="#">
				<img src="{{=URL('default', 'download', args=db.auth_user(auth.user_id).thumbnail)}}">
			</a>
			<div class="media-body">
				<div class="row-fluid">
					{{=form}}
				</div>
			</div>
		</div>	
		<div class="stream-list">									
			{{for post in posts:}}
				<div class="media stream">
					<a class="media-avatar medium pull-left" href="{{=URL('wall', vars={'auth_user_id':post.posted_by})}}">
						<img src="{{=URL('default', 'download', args=db.auth_user(post.posted_by).thumbnail)}}">
					</a>
					<div class="media-body">
						<div class="stream-headline">
							<h5 class="stream-author">
								{{if post.posted_by==post.posted_to:}}
									{{=A(name_of(post.posted_to), _href=URL('wall', vars={"auth_user_id":post.posted_to}))}}<small>{{=post.data_ora}}:</small>
								{{else:}}
									{{=A(name_of(post.posted_by), _href=URL('wall', vars={"auth_user_id":post.posted_by}))}} <i class="icon-chevron-right"></i> {{=A(name_of(post.posted_to), _href=URL('wall', vars={"auth_user_id":post.posted_to}))}}<small>{{=post.data_ora}}:</small>
								{{pass}}
							</h5>		
							<div class="stream-text">
								{{=XML(post.corpo)}}
							</div>
							<div class="stream">								
								{{=XML(getVideo("http://www.youtube.com/watch?v=zIkBvfhx64Y"))}}								
							</div>
						</div>							
						<div class="stream-options">
							{{if not db.post_likes(post_id=post.id, auth_user_id=auth.user_id):}}
								<button class="btn btn-small" onclick="ajax('{{=URL('likePost', vars={'post_id':post.id})}}',[], null);setLikeButton(jQuery(this));">
									<i class="icon-thumbs-up shaded"></i>
									{{=T("Mi piace")}}
								</button>
							{{else:}}
								<button class='btn disabled' type='button'><i class='icon-thumbs-up shaded'></i>{{=T('Ti piace')}}</button>
							{{pass}}
						</div>
						<div class="stream-respond" >
							{{div_respond_id = 'div_respond%s'%post.id}}
							<div id="{{=div_respond_id}}">
								{{for commento in db(db.post_comments.post_id==post.id).select():}}
									<div class="media stream">
										<a class="media-avatar small pull-left" href="{{=URL('wall', vars={'auth_user_id':commento.auth_user_id})}}">
											<img src="{{=URL('default', 'download', args=db.auth_user(commento.auth_user_id).thumbnail)}}">
										</a>
										<div class="media-body">
											<div class="stream-headline">
												<h5 class="stream-author">
													{{=A(name_of(commento.auth_user_id), _href=URL('wall', vars={"auth_user_id":commento.auth_user_id}))}}<small>{{=commento.data_ora}}:</small>
												</h5>
												<div class="stream-text">
													{{=XML(commento.corpo)}}
												</div>
											</div>
										</div>
									</div>
								{{pass}}
							</div>
							{{textarea_id = 'textarea_comment_%s'%post.id}}
							<textarea id="{{=textarea_id}}" placeholder="{{=T('Scrivi un commento')}}"></textarea>
							<button class='btn' type='button' onclick="commentPost(jQuery('#{{=textarea_id}}'), {{=post.id}}, jQuery('#{{=div_respond_id}}') )";></i>{{=T('Commenta')}}</button>
						</div>
					</div>
				</div>
			{{pass}}
		</div>
	</div>
</div>
